github.com/bencicandrej/quorum@v2.2.6-0.20190909091323-878cab86f711+incompatible/docs/Getting Started/7Nodes.md (about) 1 # 7nodes Example 2 ## Set Up 3 Start the 7nodes sample network by following the instructions in [7nodes Set Up](../7Nodes-Setup). 4 5 ## Demonstrating Privacy 6 The [7nodes example](https://github.com/jpmorganchase/quorum-examples/tree/master/examples/7nodes) comes with some simple contracts to demonstrate the privacy features of Quorum. 7 8 In this demo we will: 9 10 * Send a private transaction between nodes 1 and 7 11 * Show that only nodes 1 and 7 are able to view the initial state of the contract 12 * Have Node 1 update the state of the contract and, once the block containing the updated transaction is validated by the network, again verify that only nodes 1 and 7 are able to see the updated state of the contract 13 14 !!! tip 15 [Constellation](../../Privacy/Constellation/Constellation) or [Tessera](../../Privacy/Tessera/Tessera) is used to enable the privacy features of Quorum. To start a Quorum node without its associated privacy transaction manager, set `PRIVATE_CONFIG=ignore` when starting the node. 16 17 ### Sending a private transaction 18 19 Send an example private contract from Node 1 to Node 7 (this is denoted by the Node 7's public key passed via `privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]` in `private-contract.js`): 20 ``` bash 21 ./runscript.sh private-contract.js 22 ``` 23 Make note of the `TransactionHash` printed to the terminal. 24 25 ### Inspecting the Quorum nodes 26 27 We can inspect any of the Quorum nodes by using `geth attach` to open the Geth JavaScript console. For this demo, we will be inspecting Node 1, Node 4 and Node 7. 28 29 It is recommended to use separate terminal windows for each node we are inspecting. In each terminal, ensure you are in the `path/to/7nodes` directory, then: 30 31 - In terminal 1 run `geth attach ipc:qdata/dd1/geth.ipc` to attach to node 1 32 - In terminal 2 run `geth attach ipc:qdata/dd4/geth.ipc` to attach to node 4 33 - In terminal 3 run `geth attach ipc:qdata/dd7/geth.ipc` to attach to node 7 34 35 To look at the private transaction that was just sent, run the following command in one of the terminals: 36 ``` sh 37 eth.getTransaction("0xe28912c5694a1b8c4944b2252d5af21724e9f9095daab47bac37b1db0340e0bf") 38 ``` 39 where you should replace this hash with the TransactionHash that was previously printed to the terminal. This will print something of the form: 40 ``` sh 41 { 42 blockHash: "0x4d6eb0d0f971b5e0394a49e36ba660c69e62a588323a873bb38610f7b9690b34", 43 blockNumber: 1, 44 from: "0xed9d02e382b34818e88b88a309c7fe71e65f419d", 45 gas: 4700000, 46 gasPrice: 0, 47 hash: "0xe28912c5694a1b8c4944b2252d5af21724e9f9095daab47bac37b1db0340e0bf", 48 input: "0x58c0c680ee0b55673e3127eb26e5e537c973cd97c70ec224ccca586cc4d31ae042d2c55704b881d26ca013f15ade30df2dd196da44368b4a7abfec4a2022ec6f", 49 nonce: 0, 50 r: "0x4952fd6cd1350c283e9abea95a2377ce24a4540abbbf46b2d7a542be6ed7cce5", 51 s: "0x4596f7afe2bd23135fa373399790f2d981a9bb8b06144c91f339be1c31ec5aeb", 52 to: null, 53 transactionIndex: 0, 54 v: "0x25", 55 value: 0 56 } 57 ``` 58 59 Note the `v` field value of `"0x25"` or `"0x26"` (37 or 38 in decimal) which indicates this transaction has a private payload (input). 60 61 62 #### Checking the state of the contract 63 For each of the 3 nodes we'll use the Geth JavaScript console to create a variable called `address` which we will assign to the address of the contract created by Node 1. The contract address can be found in two ways: 64 65 - In Node 1's log file: `7nodes/qdata/logs/1.log` 66 - By reading the `contractAddress` param after calling `eth.getTransactionReceipt(txHash)` ([Ethereum API documentation](https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransactionreceipt)) where `txHash` is the hash printed to the terminal after sending the transaction. 67 68 Once you've identified the contract address, run the following command in each terminal: 69 ``` javascript 70 > var address = "0x1932c48b2bf8102ba33b4a6b545c32236e342f34"; //replace with your contract address 71 ``` 72 73 Next we'll use ```eth.contract``` to define a contract class with the simpleStorage ABI definition in each terminal: 74 ``` javascript 75 > var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"type":"constructor"}]; 76 > var private = eth.contract(abi).at(address) 77 ``` 78 79 The function calls are now available on the contract instance and you can call those methods on the contract. Let's start by examining the initial value of the contract to make sure that only nodes 1 and 7 can see the initialized value. 80 81 - In terminal window 1 (Node 1): 82 ``` javascript 83 > private.get() 84 42 85 ``` 86 - In terminal window 2 (Node 4): 87 ``` javascript 88 > private.get() 89 0 90 ``` 91 - In terminal window 3 (Node 7): 92 ``` javascript 93 > private.get() 94 42 95 ``` 96 97 So we can see nodes 1 and 7 are able to read the state of the private contract and its initial value is 42. If you look in `private-contract.js` you will see that this was the value set when the contract was created. Node 4 is unable to read the state. 98 99 ### Updating the state of the contract 100 101 Next we'll have Node 1 set the state to the value `4` and verify only nodes 1 and 7 are able to view the new state. 102 103 In terminal window 1 (Node 1): 104 ``` javascript 105 > private.set(4,{from:eth.accounts[0],privateFor:["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}); 106 "0xacf293b491cccd1b99d0cfb08464a68791cc7b5bc14a9b6e4ff44b46889a8f70" 107 ``` 108 You can check the log files in `7nodes/qdata/logs/` to see each node validating the block with this new private transaction. Once the block containing the transaction has been validated we can once again check the state from each node 1, 4, and 7. 109 110 - In terminal window 1 (Node 1): 111 ``` javascript 112 > private.get() 113 4 114 ``` 115 - In terminal window 2 (Node 4): 116 ``` javascript 117 > private.get() 118 0 119 ``` 120 - In terminal window 3 (Node 7): 121 ``` javascript 122 > private.get() 123 4 124 ``` 125 And there you have it; all 7 nodes are validating the same blockchain of transactions, the private transactions carrying only a 512 bit hash on-chain, and only the parties to private transactions being able to view and update the state of private contracts. 126 127 ## Permissions 128 129 Node Permissioning is a feature in Quorum that allows only a pre-defined set of nodes (as identified by their remotekey/enodes) to connect to the permissioned network. 130 131 In this demo we will: 132 133 - Set up a network with a combination of permissioned and non-permissioned nodes in the cluster 134 - Look at the details of the `permissioned-nodes.json` file 135 - Demonstrate that only the nodes that are specified in `permissioned-nodes.json` can connect to the network 136 137 ### Verify only permissioned nodes are connected to the network. 138 139 Attach to the individual nodes via `geth attach path/to/geth.ipc` and use `admin.peers` to check the connected nodes: 140 141 ``` sh 142 ❯ geth attach qdata/dd1/geth.ipc 143 Welcome to the Geth JavaScript console! 144 145 instance: Geth/v1.7.2-stable/darwin-amd64/go1.9.2 146 coinbase: 0xed9d02e382b34818e88b88a309c7fe71e65f419d 147 at block: 1 (Mon, 29 Oct 47909665359 22:09:51 EST) 148 datadir: /Users/joel/jpm/quorum-examples/examples/7nodes/qdata/dd1 149 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 raft:1.0 rpc:1.0 txpool:1.0 web3:1.0 150 151 > admin.peers 152 [{ 153 caps: ["eth/63"], 154 id: "0ba6b9f606a43a95edc6247cdb1c1e105145817be7bcafd6b2c0ba15d58145f0dc1a194f70ba73cd6f4cdd6864edc7687f311254c7555cc32e4d45aeb1b80416", 155 name: "Geth/v1.7.2-stable/darwin-amd64/go1.9.2", 156 network: { 157 localAddress: "127.0.0.1:65188", 158 remoteAddress: "127.0.0.1:21001" 159 }, 160 protocols: { 161 eth: { 162 difficulty: 0, 163 head: "0xc23b4ebccc79e2636d66939924d46e618269ca1beac5cf1ec83cc862b88b1b71", 164 version: 63 165 } 166 } 167 }, 168 ... 169 ] 170 ``` 171 172 You can also inspect the log files under `qdata/logs/*.log` for further diagnostics messages around incoming / outgoing connection requests. `grep` for `ALLOWED-BY` or `DENIED-BY`. Be sure to enable verbosity for p2p module. 173 174 ### Permissioning configuration 175 176 Permissioning is granted based on the remote key of the geth node. The remote keys are specified in the `permissioned-nodes.json` and is placed under individual node's `<datadir>`. 177 178 The below sample `permissioned-nodes.json` provides a list of nodes permissioned to join the network (node ids truncated for clarity): 179 180 ``` json 181 [ 182 "enode://8475a01f22a1f48116dc1f0d22ecaaaf77e@127.0.0.1:30301", 183 "enode://b5660501f496e60e59ded734a889c97b7da@127.0.0.1:30302", 184 "enode://54bd7ff4bd971fb80493cf4706455395917@127.0.0.1:30303" 185 ] 186 ``` 187 188 ### Enabling/Disabling permissions 189 190 An individual node can enable/disable permissioning by passing the `-permissioned` command line flag. If enabled, then only the nodes that are in the `<datadir>/permissioned-nodes.json` can connect to it. Further, these are the only nodes that this node can make outbound connections to as well. 191 192 ``` 193 MISCELLANEOUS OPTIONS: 194 --permissioned If enabled, the node will allow only a defined list of nodes to connect 195 ``` 196 197 ## Next steps 198 Additional samples can be found in `quorum-examples/examples/7nodes/samples` for you to use and edit. You can also create your own contracts to help you understand how the nodes in a Quorum network work together. 199 200 Take a look at [Creating a Network From Scratch](../Creating-A-Network-From-Scratch) for step-by-step instructions on how to create your own Quorum network. 201